﻿<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>配置管理平台登录</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="lib/layui/css/layui.css" rel="stylesheet" />
    <link href="x-admin/css/font.css" rel="stylesheet" />
    <link href="x-admin/css/xadmin.css" rel="stylesheet" />
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
</head>
<body class="login-bg">

    <div class="login layui-anim layui-anim-up">
        <div class="message">配置管理平台登录</div>
        <div id="darkbannerwrap"></div>

        <form class="layui-form">
            <input name="name" placeholder="用户名" id="name" type="text" lay-verify="required" class="layui-input" autocomplete="off">
            <hr class="hr15">
            <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input" autocomplete="off">
            <hr class="hr15">
            <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr20">
        </form>
    </div>

    <script>
        layui.use('form', function () {
            var form = layui.form;
            var $ = layui.$;
            //监听提交
            form.on('submit(login)', function (data) {
                data.field.IsVerifyPassword = true;
                layui.$.ajax({
                    type: "post",
                    cache: false,
                    url: gethosttingadr() + '/api/UserAuthority/loginverify',
                    data: JSON.stringify(data.field),
                    success: function (da) {
                        setCookie('userinfo', da.user, 1);
                        location.href = 'index.html'
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        layer.msg("用户信息验证失败！", function () {
                            layui.$("input[name='username']").focus();
                        });
                    }
                });
                return false;
            });


        });

        function setCookie(name, value, iDay) {
            var oDate = new Date();
            oDate.setDate(oDate.getDate() + iDay); //用来设置过期时间用的，获取当前时间加上传进来的iDay就是过期时间
            document.cookie = name + '=' + value + ';expires=' + oDate;
        };
        function getCookie(name) {
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            if (arr = document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return '';
        };
        function removeCookie(name) {
            setCookie(name, 1, -1); //-1就是告诉系统已经过期，系统就会立刻去删除cookie
        };
        //进行将请求地址缓存下来
        function gethosttingadr() {
            //删除某个键值对
            localStorage.removeItem('hosttingaddr');
            //获取配置内容
            layui.jquery.ajax({
                url: "../jsconfig.json",
                async: false,
                type: "GET",
                cache: false,
                dataType: "json",
                success: function (json) {
                    // 写入数据
                    localStorage.setItem('hosttingaddr', json.appsetting.hosttingaddr);
                }
            });
            var addr = localStorage.getItem('hosttingaddr');
            return addr;
        }
    </script>
</body>
</html>